﻿using OpenCvSharp.WpfExtensions;
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ScienceAIApp.Views.ToolBarPanel;
/// <summary>
/// Interaction logic for DrawBrushView.xaml
/// </summary>
public partial class DrawBrushView
{
    public DrawBrushView()
    {
        InitializeComponent();
        this.WhenActivated(_activated);
    }

    private void _activated(CompositeDisposable disposable)
    {
        this.OneWayBind(
            ViewModel,
            vm => vm.SelectedBrush,
            v => v.SegBlock.Foreground
        ).DisposeWith(disposable);

        this.OneWayBind(ViewModel,
            vm => vm.BorderThicknessMat,
            v => v.BrushThicknessImg.Source,
            image =>
            {
                var result = image?.ToWriteableBitmap();
                return result;
            }).DisposeWith(disposable);

        // 下拉框绑定
        this.Bind(
            ViewModel,
            vm => vm.SelectedDrawTypeIndex,
            v => v.SegTypeCombox.SelectedIndex
        ).DisposeWith(disposable);


        this.BindCommand(
            ViewModel, 
            vm => vm.AdjustBrushThincknessCommand, 
            v => v.PreBlock,
            Observable.Return(false)
            ).DisposeWith(disposable);

        this.BindCommand(
            ViewModel,
            vm => vm.AdjustBrushThincknessCommand,
            v => v.NextBlock,
            Observable.Return(true)
        ).DisposeWith(disposable);
        
        // 保存勾画数据
        this.BindCommand(
            ViewModel,
            vm => vm.SaveDrawCommand,
            v => v.SaveSegBtn
        ).DisposeWith(disposable);

        this.OneWayBind(
            ViewModel,
            vm=>vm.IsShowDrawPanel,
            v=>v.DrawPanel.Visibility
            ).DisposeWith(disposable);

        this.OneWayBind(
            ViewModel,
            vm => vm.BorderThickness,
            v=>v.BrushThicknessTxt.Text
            ).DisposeWith(disposable);



    }
}
